package zezutom.joker.service;

import javax.annotation.Resource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.impl.Log4jLoggerAdapter;
import zezutom.joker.model.BadJokeException;
import zezutom.joker.model.Joke;
import zezutom.joker.model.Joker;
import zezutom.joker.model.RepeatedJokeException;

/**
 * Television (TV) is a telecommunication medium for transmitting
 * and receiving moving images that can be monochrome (black-and-white)
 * or colored, with accompanying sound. 
 * 
 * Wikipedia (http://en.wikipedia.org/wiki/Television)
 * 
 * @author tomasz
 */
public class Telly {

    private Logger logger = LoggerFactory.getLogger(Telly.class);
    
    @Resource(name="funnyService")
    private FunnyService service;
    
    public void oneTrickPonyShow() {
    
        for (Joker joker : service.loadCircus()) {
            
            try {
                for (Joke joke : service.saySomethingFunny(joker.getId())) {
                    logger.info(joke.toString());
                }                
            } catch (BadJokeException ex) {
                logger.error(ex.getMessage());            
            } catch (RepeatedJokeException ex) {
                logger.error(ex.getMessage());
            }
        }
    }
}
